import { fileURLToPath, URL } from 'node:url'
import Components from 'unplugin-vue-components/vite'
import { VantResolver } from 'unplugin-vue-components/resolvers'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    Components({
      resolvers: [VantResolver()]
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    proxy: {
      '/wangYi': {
        // 匹配所有以 /api 开头的请求路径
        target: 'https://m.you.163.com', // 代理目标的基础路径
        changeOrigin: true,
        rewrite: (path: any) => path.replace(/^\/wangYi/, '')
      },
      '/sph': {
        target: 'http://sph-h5-api.atguigu.cn/', // 代理目标的基础路径
        changeOrigin: true,
        rewrite: (path: any) => path.replace(/^\/sph/, '')
      }
    }
  }
})
